package com.burgeon.backend.EnterpriseWeChat.rest.VipInfo;

import com.burgeon.backend.EnterpriseWeChat.entity.VipFeature;
import com.burgeon.backend.EnterpriseWeChat.entity.VipRelation;
import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class queryRelationList extends RESTBase {
    private final static String RANGE = "20";//分页数量
    private String ip;
    private String account;
    private String password;

    public queryRelationList(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     *
     * @return
     */

    public ArrayList<VipRelation>  getData() throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(), url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        if (!"0".equals(code)) {
            throw new Exception(new JSONArray(str).getJSONObject(0).getString("message"));
        }

        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
        ArrayList<VipRelation> vipRelations = new ArrayList<>();
        for (int i = 0; i < jsonArray.length(); i++) {
            VipRelation vipRelation= new VipRelation();
            if(jsonArray.length()>0){
                vipRelation.setValue(jsonArray.getJSONArray(i).getString(0));
                vipRelation.setDescription(jsonArray.getJSONArray(i).getString(1));
                vipRelations.add(vipRelation);
         }

        }

        return vipRelations;
    }

    private MultiValueMap Data() {
        HashMap params = new HashMap();
        ArrayList colums = new ArrayList();//查询字段

        colums.add("VALUE");
        colums.add("DESCRIPTION");

        params.put("columns", colums);

        params.put("table", "AD_LIMITVALUE");//表名
        params.put("count","true");

        HashMap paramss = new HashMap();
        paramss.put("column","'AD_LIMITVALUE_GROUP_ID;NAME'");
        paramss.put("condition","'CALL_TYPE'");


        params.put("params",paramss);
        System.err.println(params);

        return DATA("Query", params, account, password);
    }

    public static void main(String[] args) {
        queryRelationList g = new queryRelationList("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {//3125
            System.err.println(g.getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
